package com.haredot.mapper;

import com.haredot.dto.BindMenuSysDto;
import com.haredot.dto.BindSysMenuDto;
import com.haredot.entity.Menu;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;
import java.util.Map;

@Mapper
public interface MenuMapper {

    Menu findMenuByName(String menuName);

    @CacheEvict(value = "menu:all", allEntries = true)
    int insert(Menu menu);

    List<Menu> findMenusByCondition(Map<String, Object> params);

    @Cacheable(value = "menu:bind:sys", key = "#a0")
    List<BindSysMenuDto> findBindSysByMenuId(Long menuId);

    @CacheEvict(value = "menu:bind:sys", key = "#a0")
    int removeSysByMenuId(Long menuId);

    int batchInsertSysByMenuId(@Param("menuId") Long menuId, @Param("sysIds") List<Long> sysIds);

    @CacheEvict(value = "menu:all", allEntries = true)
    int batchRemoveByMenus(List<Long> menuIds);

    @CacheEvict(value = "menu:all", allEntries = true)
    int updateMenuById(Menu menu);

    List<BindMenuSysDto> findSysBindMenuListBySysId(Long sysId);

    @CacheEvict(value = "menu:all", allEntries = true)
    int deleteById(Long menuId);
}